<template>
  <div style="background-color:#f7f8fa; height: 100vh;">
    <van-nav-bar right-text="退出登陆" title="首页" @click-right="onClickLeft"/>
    <div style="height: 3rem;"></div>
    <van-image :src="image" class="iamge" fit="contain" height="10rem" position="center"/>
    <div class="button-padding">
      <van-button block round size="large" to="querystatus" type="primary">结果查询</van-button>
    </div>
    <div class="button-padding">
      <van-button block round size="large" type="primary" @click="goFillin">填写报名信息</van-button>
    </div>
  </div>
</template>

<script>
import {useRouter} from 'vue-router'
import {useCounterStore} from '../../pinia/user'
import image from '../../assets/logo111.jpg'
import {Base64} from 'js-base64'
import {getCardInfo} from '@/api/Fillln.js'
import {Toast} from 'vant'

export default {
  setup(props) {
    const CounterStore = useCounterStore()
    const router = useRouter()

    function onClickLeft() {
      CounterStore.getToken('')
      router.push('/')
    }

    const data = reactive({data: ''})
    // 获取当前员工是否存在信息记录
    getCardInfo(CounterStore.mobile).then(res => {
      // 不存在的话 测创建默认值
      if (!res.message) res.message = {employeeType: '', isSubmit: 0}
      //  将获取到的信息 解构
      const {employeeType, isSubmit} = res.message
      //  判断当前员工是否提交  并且有员工职位信息
      if (+isSubmit === 1 && employeeType) {
        const a = +employeeType === 1 ? 'regular' : +employeeType === 2 ? 'dispatched' : +employeeType === 3 ? 'Hours' : +employeeType === 4 ? 'trainee' : ''
        CounterStore.setHireType(a)
      }
      data.data = Base64.encode(JSON.stringify(res.message))
    })


    function goFillin() {
      if (data.data) {
        router.push({
          path: '/fillin',
          query: {data: data.data}
        })
      } else {
        Toast.fail('点太快了，请重试！！')
      }
    }

    return {
      goFillin,
      onClickLeft,
      image
    }
  }
}


</script>


<style scoped>
.button-padding {
  margin-top: 2rem;
  padding: 0 2.5rem;
}

.iamge {
  padding: 3rem 2rem;
}
</style>
